package com.example.laboratory.ui.user.Laboratory;

import com.example.laboratory.application.LApp;
import com.example.laboratory.bean.Laboratory;
import com.example.laboratory.manager.UserInfoManager;
import com.example.laboratory.net.callback.RxObserver;
import com.example.laboratory.ui.core.model.impl.UserModel;
import com.example.laboratory.ui.core.presenter.BasePresenter;

import java.util.List;


/**
 * 和用户相关的Presenter
 * author: 康栋普
 * date: 2018/3/21
 */

public class  LabPresenter extends BasePresenter<LabContract.ILabView> implements LabContract.ILabPresenter {
    private LabContract.ILabView iLabView;
    private UserModel mUserModel;

    public LabPresenter() {
        this.mUserModel = new UserModel();
    }
    @Override
    public void loadLaboratoryList(String uid, String departId) {
        iLabView = getView();
        RxObserver<Laboratory> mLaboratoryRxPageList=new RxObserver<Laboratory>(this) {
            @Override
            protected void onSuccess(Laboratory data) {
                List<Laboratory.RowsBean> rowsBeans=data.getRows();
                iLabView.setData(rowsBeans);
                    if (iLabView.getData().size() == 0)
                        iLabView.showEmpty();
                    else
                        iLabView.showContent();

            }

            @Override
            protected void onFail(int errorCode, String errorMsg) {
                iLabView.showFail(errorMsg);
            }
        };
        mUserModel.getLaboratoryList(1,4,uid,departId,mLaboratoryRxPageList);
        addDisposable(mLaboratoryRxPageList);
    }

    @Override
    public void loadLabList(String uid, String departId) {
        iLabView = getView();
        RxObserver<Laboratory> mLaboratoryRxPageList=new RxObserver<Laboratory>(this) {
            @Override
            protected void onSuccess(Laboratory data) {
                List<Laboratory.RowsBean> rowsBeans=data.getRows();
                iLabView.setData(rowsBeans);
            }

            @Override
            protected void onFail(int errorCode, String errorMsg) {
                iLabView.showFail(errorMsg);
            }
        };
        mUserModel.getLaboratoryList(1,4,uid,departId,mLaboratoryRxPageList);
        addDisposable(mLaboratoryRxPageList);
    }
}
